<?php

namespace App\Models\Traits;

use Illuminate\Database\Eloquent\Casts\Attribute;

trait HasAvatarAttribute
{
    public function avatar(): Attribute
    {
        return new Attribute(
            get: fn(string $path) =>  \Str::startsWith($path, ['https://', 'http://']) ? $path: ($path ? \Storage::url($path) : url('images/default_avatar.jpg'))
        );
    }
}
